<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>圆心渐变</title>
    <style>
        body{
            height: 100vh;
            width: 100vw;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        canvas {
            border: dashed 2px #ccc;
        }
    </style>
    <script>
        function $$(id){
          return document.getElementById(id);
        }
        function pageLoad(){
            let can = $$('can');
            let cans = can.getContext('2d');
            const gnt1 = cans.createRadialGradient(200,300,50,200,200,200);
            gnt1.addColorStop(1,'red');
            gnt1.addColorStop(0,'green');
            cans.fillStyle = gnt1;
            cans.fillRect(0,0,800,600);

            let can2 = $$('can2')
            let cans2 = can2.getContext('2d');
            cans2.beginPath();
            cans2.arc(200,150,100,0,Math.PI*2,true);
            // cans.arc(200,150,100,0,Math.PI/2,true);
            cans2.closePath();
            var gnt = cans2.createRadialGradient(200,150,0,200,50,250);
            gnt.addColorStop(0,'red');
            gnt.addColorStop(1,'#333');
            cans2.fillStyle = gnt;
            cans2.fill();
        }
    </script>
</head>
<body onload="pageLoad()">
    <canvas id="can" width="800px" height="600px">4</canvas>
    <canvas id="can2" width="800px" height="600px">1</canvas>
</body>
</html>